<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="请输入您猜的数字" v-model="numOf">
  <button @click="guess">猜一猜</button>
  <h4>您猜的结果是{{result}}</h4>


</template>

<script setup>
import {ref} from "vue";

let num = parseInt(Math.random() * 100+1);
console.log(num);
const numOf = ref('');
const result = ref('');

const guess = () => {
  if (numOf.value.trim() == ''){
    numOf.value = '';
    alert('请输入数字')
    return;
  }
  if (numOf.value > num) {
     result.value = "猜大了";
  } else if (numOf.value < num) {
     result.value = "猜小了";
  } else {
     result.value = "恭喜你猜对了";
  }
}
</script>

<style scoped>

</style>